package com.me.mygdxgame.planet;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class PlanetParallaxLayer {
	
	private float x, y, factor;
	
	private Sprite layer;
	private SpriteBatch spriteBatch;

	public PlanetParallaxLayer(Texture texture, float x, float y, float f) {
		this.x = x;
		this.y = y;
		this.factor = f;
		
		this.layer = new Sprite(texture);
		this.spriteBatch = new SpriteBatch();
	}
	
	
	public void render(float delta, float cameraXVelocity) {
		// Calculate the change in position
		this.x -= (cameraXVelocity * this.factor * delta);
		float rightEdge = this.x + this.layer.getWidth();
		//TODO
		this.spriteBatch.begin();
		this.spriteBatch.draw(layer, this.x, this.y);
		if (rightEdge < Gdx.graphics.getWidth()) {
			this.spriteBatch.draw(layer, rightEdge, this.y);
			if (rightEdge < 0f)
				this.x = rightEdge;
		}
		this.spriteBatch.end();
	}
}
